
gl repo "~/Replication repo/"
gl data "~/Replication repo/data"

gl orders post_emergency post_gather post_schools post_resto post_neb post_stayhome
gl demogs med_age loginc sh_over65 sh_black sh_hisp sh_male pop_dens
gl covid covid_cases state_deaths
gl tweets post_tweet_covid post_tweet_social_dist

use "$repo_data/SG_county_data", clear

**Figure 2: Event study: Governors’ Stay Home Tweets by Counties’ Partisanship**

forvalues p = 0/1 {

if `p' == 1 {

local note "Republican county"

}

if `p' == 0 {

local note "Democratic county"

}

local y median_home
local lab : var lab `y'

reghdfe  stay_homedum1-stay_homedum9 stay_homedum11-stay_homedum26 $tweets $covid $orders ///
	if trump_county==`p', absorb(ccode day day#c.($demogs trump_margin)) cl(statefp)
	
	gen b = .
	gen ub = .
	gen lb = .
	gen t = .
	
	local i = 0
	foreach z of numlist 1/9 11/26 {
	local i = `i' + 1
	
		replace b = _b[c.stay_homedum`z'] in `i'
		replace ub = b + 1.96*_se[c.stay_homedum`z'] in `i'
		replace lb = b - 1.96*_se[c.stay_homedum`z'] in `i'
		replace t  = `z'-11 in `i'
		
		}
		
		replace t = -1 in 27
		replace b = 0 if t==-1
		replace ub = 0 if t==-1
		replace lb = 0 if t==-1

	sort t
	
	twoway rcap ub lb t, lpatt(dash) lcol(black)  ///
	|| scatter b t, msy(D)  mcol(black) ///
	scheme(plotplain) xline(0) yline(0) legend(off) scale(0.9) ///
	ytitle("`lab'") xtitle("Day relative to tweet") xscale(r(-10 7) extend) xlab(-10(5)15)  ///
	note("`note'") name(`y'_`p', replace)
	
	drop b ub lb t


	}
	
	graph combine `y'_0 `y'_1, scheme(plotplain) scale(1.5) xcommon ycommon cols(2) ysize(2) graphregion(margin(zero))
	graph export "$repo/`y'_govtweets_byGOPcounty.pdf", replace

**Figure 3: Predictive margins: effect of “stay home” tweet by Trump vote share and governor party**
//by dem/rep
interflex median_home post_tweet_stay_home trump_margin  $tweets $covid $orders ddum_*  if rep_gov==0, ///
	fe(day ccode) cl(ccode) xlab("Trump margin") type(binning) cutoffs(-0.25 0 0.25 0.5) ///
	dlab("stay home tweet") ylab("time at home") ///
	xrange(-0.8 0.9) yrange(-40 60) 
	graph export "$repo/interflex_DEM_binsonly.pdf", replace
	
interflex median_home post_tweet_stay_home trump_margin  $tweets $covid $orders ddum_* if rep_gov==1, ///
	fe(day ccode day) cl(ccode)  xlab("Trump margin") type(binning) cutoffs(-0.25 0 0.25 0.5) ///
	dlab("stay home tweet") ylab("time at home") ///
	xrange(-0.8 0.9) yrange(-40 60)
	graph export "$repo/interflex_GOP_binsonly.pdf", replace


**Figure SI-6: Mobility relative to stay at home orders**

	foreach y in sh_home_allday median_home logtimehome logdist {
	
		local lab : var lab `y'

		binsreg `y' etime if  inrange(etime,-10,10), line(3,3)  ///
		ci(3,3) ciplotopt(lpatt(dash) lcol(black)) dotsplotopt(msym(d) ///
		mcol(black)) cb(3,3) polyreg(3)  by(post_stayhome) bycolors(black black) ///
		scheme(plotplain) name(c`i'g`j', replace) legend(off) xline(0) ///
		xtitle("Day relative to lockdown") ytitle("`lab'") scale(0.9)
		
		graph export "$repo/`y'_lockdown_bin.pdf", replace

	}


**Figure SI-7: Event study: governor tweets “stay home,” baseline effects**
foreach y in  median_home logtimehome sh_home_all logdist {

local lab : var lab `y'

reghdfe `y' c.(stay_homedum1-stay_homedum9 stay_homedum11-stay_homedum26) $tweet $covid  $orders, ///
	absorb(ccode day day#c.($demogs trump_margin)) cl(statefp)
	
	gen b = .
	gen ub = .
	gen lb = .
	gen t = .
	
	local i = 0
	foreach z of numlist 1/9 11/26 {
	local i = `i' + 1
	
		replace b = _b[c.stay_homedum`z'] in `i'
		replace ub = b + 1.96*_se[c.stay_homedum`z'] in `i'
		replace lb = b - 1.96*_se[c.stay_homedum`z'] in `i'
		replace t  = `z'-11 in `i'
		
		}
		
		replace t = -1 in 27
		replace b = 0 if t==-1
		replace ub = 0 if t==-1
		replace lb = 0 if t==-1

	sort t
	
	twoway rcap ub lb t, lpatt(dash) lcol(black)  ///
	|| scatter b t, msy(D) mcol(black) ///
	scheme(plotplain) xline(0) yline(0) legend(off) scale(0.9) ///
	ytitle("`lab'") xtitle("Day relative to tweet") xscale(r(-10 7) extend) xlab(-10(5)15)  
	
	graph export "$repo/`y'_govtweets_agg.pdf", replace

	drop b ub lb t


	}



**Figure SI-8: Event study: governor tweets “stay home,” by partisan lean**
foreach y in logtimehome sh_home_allday logdist  {

forvalues p = 0/1 {

if `p' == 1 {

local note "Republican county"

}

if `p' == 0 {

local note "Democratic county"

}

local lab : var lab `y'


reghdfe `y' stay_homedum1-stay_homedum9 stay_homedum11-stay_homedum26 $tweets $covid $orders ///
	if trump_county==`p', absorb(ccode day day#c.($demogs trump_margin)) cl(statefp)
	
	gen b = .
	gen ub = .
	gen lb = .
	gen t = .
	
	local i = 0
	foreach z of numlist 1/9 11/26 {
	local i = `i' + 1
	
		replace b = _b[c.stay_homedum`z'] in `i'
		replace ub = b + 1.96*_se[c.stay_homedum`z'] in `i'
		replace lb = b - 1.96*_se[c.stay_homedum`z'] in `i'
		replace t  = `z'-11 in `i'
		
		}
		
		replace t = -1 in 27
		replace b = 0 if t==-1
		replace ub = 0 if t==-1
		replace lb = 0 if t==-1

	sort t
	
	twoway rcap ub lb t, lpatt(dash) lcol(black)  ///
	|| scatter b t, msy(D)  mcol(black) ///
	scheme(plotplain) xline(0) yline(0) legend(off) scale(0.9) ///
	ytitle("`lab'") xtitle("Day relative to tweet") xscale(r(-10 7) extend) xlab(-10(5)15)  ///
	note("`note'") name(`y'_`p', replace)
	
	drop b ub lb t


	}
	
	graph combine `y'_0 `y'_1, scheme(plotplain) scale(1.5) xcommon ycommon cols(2) ysize(2) graphregion(margin(zero))
	graph export "$repo/`y'_govtweets_byGOPcounty.pdf", replace


}
	
	
**Figure SI-9: Event study: governor tweets “stay home,” Google searches**
use "$data/gtrends_dma_data", clear

local y stay_at_home
local lab : var lab `y'

reghdfe `y' stay_homedum1-stay_homedum9 stay_homedum11-stay_homedum26, absorb(dcode day day#c.trump_margin) cl(dcode)
	
	gen b = .
	gen ub = .
	gen lb = .
	gen t = .
	
	local i = 0
	foreach z of numlist 1/9 11/26 {
	local i = `i' + 1
	
		replace b = _b[c.stay_homedum`z'] in `i'
		replace ub = b + 1.96*_se[c.stay_homedum`z'] in `i'
		replace lb = b - 1.96*_se[c.stay_homedum`z'] in `i'
		replace t  = `z'-11 in `i'
		
		}
		
		replace t = -1 in 27
		replace b = 0 if t==-1
		replace ub = 0 if t==-1
		replace lb = 0 if t==-1

	sort t
	
	twoway rcap ub lb t, lpatt(dash) lcol(black)  ///
	|| scatter b t, msy(D) mcol(black) ///
	scheme(plotplain) xline(0) yline(0) legend(off) scale(0.9) ///
	ytitle("`lab'") xtitle("Day relative to tweet") xscale(r(-10 7) extend) xlab(-10(5)15)  
	
	graph export "$repo/`y'_govtweets_agg.pdf", replace

	drop b ub lb t

**Figure SI-10: Predictive margins: effect of “stay home” tweet by Trump vote share, full sample**
use "$repo_data/SG_county_data", clear

interflex median_home post_tweet_stay_home trump_margin $tweets $covid $orders ddum_*, ///
	fe(day ccode) cl(ccode) xlab("Trump margin") type(binning) cutoffs(-0.25 0 0.25 0.5) ///
	dlab("stay home tweet") ylab("time at home") ///
	xrange(-0.8 0.9) yrange(-40 60) 
	graph export "$repo/interflex_ALL_binsonly.pdf", replace
	

interflex median_home post_tweet_stay_home trump_margin $tweets $covid $orders ddum_* [aw=tot_pop], ///
	fe(day ccode) cl(ccode) xlab("Trump margin") type(binning) cutoffs(-0.25 0 0.25 0.5) ///
	dlab("stay home tweet") ylab("time at home") ///
	xrange(-0.8 0.9) yrange(-40 60) 
	graph export "$repo/interflex_ALL_binsonly_popwt.pdf", replace


**Figure SI-11: Predictive margins: effect of “stay home” tweet by Trump vote share, full sample, nonparametric estimation**
preserve
	keep if inrange(trump_margin,-0.5,0.75)
	
	interflex median_home_dwell post_tweet_stay_home trump_margin $tweets $covid $orders ddum_*, ///
	fe(day ccode) cl(ccode) xlab("Trump margin") type(kernel) bw(0.08) ///
	dlab("stay home tweet") ylab("time at home") ///
	xrange(-0.5 0.75) yrange(-40 60) 
	graph export "$repo/interflex_ALL_binsonly_nonpar.pdf", replace
	
restore


**Figure SI-12: Distribution of Trump’s 2016 vote margin**
	use "$data/precinct_data", clear
	
	keep if cbgtag==1
	
	keep trump_margin
	
	gen type="cbg"
	
	kdensity trump_margin, nograph gen(x h)
	
	egen tot = sum(h)
	
	gen frac = h/tot
	
	drop if mi(x)
	
	keep frac x type
	
	tempfile temp1
	
	save `temp1', replace
	
	
	use "$safegraph/SG_county_data", clear
	
	keep if ctag==1
	
	keep trump_margin
	
	gen type="county"
	
	kdensity trump_margin, nograph gen(x h)
	
	egen tot = sum(h)
	
	gen frac = h/tot
	
	drop if mi(x)
	
	keep frac x type
	
	append using `temp1'

	
	twoway line frac x if type=="cbg" || line frac x if type=="county" ///
	, legend(order(1 "CBG/Precinct" 2 "County") ring(0) pos(11)) ///
	ytitle("Fraction") scale(0.9) xlab(,nogrid) 
	
	graph export "$repo/vote_dist.pdf", replace
